from django.conf.urls import url

from . import views_modelviewset,views_genericviewset,views_viewset,view_apiview,views_genericapiview,views_mixinview,views_mixinchildview
from rest_framework.routers import SimpleRouter,DefaultRouter
urlpatterns = [

    # url(r'^drf_books/$',views.BooksView.as_view()),
    # # 单一数据
    # url(r'^drf_books/(?P<pk>\d+)/$',views.BookView.as_view()),
    # APIView的使用
    # url(r'^drf_books/$',view_apiview.BooksAPIView.as_view()),
    # url(r'^drf_books/(?P<pk>\d+)/$',view_apiview.BookAPIView.as_view()),
    # GenericAPIView的使用
    # url(r'^drf_books/$',views_genericapiview.BooksGenericAPIView.as_view()),
    # url(r'^drf_books/(?P<pk>\d+)/$',views_genericapiview.BookGenericAPIView.as_view()),
    # # 拓展类的使用
    # url(r'^drf_books/$',views_mixinview.BooksMiXinView.as_view()),
    # url(r'^drf_books/(?P<pk>\d+)/$',views_mixinview.BookMiXinView.as_view()),
    # 拓展类子类的使用
    # url(r'^drf_books/$',views_mixinchildview.BooksMiXinView.as_view()),
    # url(r'^drf_books/(?P<pk>\d+)/$',views_mixinchildview.BookMiXinView.as_view()),
    # 视图集路由匹配
    url(r'^viewset_books/$',
        views_viewset.BooksViewSet.as_view({'get':'list','post':'create'})),
    url(r'^viewset_books/(?P<pk>\d+)/$',
        views_viewset.BookViewSet.as_view({'get':'retrieve','put':'update','delete':'destroy'})),
    # # GenericViewSet
    # url(r'^genericviewset_books/$',
    #     views_genericviewset.BooksGenericViewSet.as_view({'get':'list','post':'create'})),
    # url(r'^genericviewset_books/(?P<pk>\d+)/$',
    #     views_genericviewset.BookGenericViewSet.as_view({'get':'retrieve','put':'update','delete':'destroy'})),
    # # ModelViewSet
    # url(r'^modelviewset_books/$',
    #     views_modelviewset.BookModelViewSet.as_view({'get':'list','post':'create'})),
    # url(r'^modelviewset_books/(?P<pk>\d+)/$',
    #     views_modelviewset.BookModelViewSet.as_view({'get':'retrieve','put':'update','delete':'destroy'})),
    # # 自定义方法,方法名做路径
    # url(r'^modelviewset_books/last_book/$',
    #     views_modelviewset.BookModelViewSet.as_view({'get':'last_book'})),
    # url(r'^modelviewset_books/find/$',
    #     views_modelviewset.BookModelViewSet.as_view({'get':'find'})),
    # 视图集可以使用自动路由生成

]
# 生成路由类对象
router=DefaultRouter()
# 自动生成路由的方法必须配合视图集使用，普通视图不行
router.register('modelviewset_books',views_modelviewset.BookModelViewSet,base_name='book')
print(router.urls)
# 添加到原有的路由列表中
urlpatterns += router.urls

# DefaultRouter与SimpleRouter使用方法一致，区别在于首页的匹配，DefaultRouter会进行首页匹配，SimpleRouter不会